package com.psycho.sys.api.controller;

import com.psycho.sys.api.common.Result;
import com.psycho.sys.api.entity.Appointment;
import com.psycho.sys.api.entity.Counselor;
import com.psycho.sys.api.entity.ConsultationRecord;
import com.psycho.sys.api.service.CounselorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 咨询师控制器
 */
@RestController
@RequestMapping("/api/counselor")
public class CounselorController {

    @Autowired
    private CounselorService counselorService;

    /**
     * 获取咨询师个人信息
     */
    @GetMapping("/profile")
    public Result<Counselor> getProfile(@RequestParam Long counselorId) {
        return Result.success(counselorService.getCounselorProfile(counselorId));
    }

    /**
     * 更新咨询师个人信息
     */
    @PutMapping("/profile")
    public Result<Boolean> updateProfile(@RequestBody Counselor counselor) {
        return Result.success(counselorService.updateCounselorProfile(counselor));
    }

    /**
     * 获取待处理的预约请求
     */
    @GetMapping("/appointments/pending")
    public Result<List<Appointment>> getPendingAppointments(@RequestParam Long counselorId) {
        return Result.success(counselorService.getPendingAppointments(counselorId));
    }

    /**
     * 更新预约状态
     */
    @PutMapping("/appointments/{id}/status")
    public Result<Boolean> updateAppointmentStatus(
            @PathVariable("id") Long appointmentId,
            @RequestParam Integer status,
            @RequestParam(required = false) String reason) {
        return Result.success(counselorService.updateAppointmentStatus(appointmentId, status, reason));
    }

    /**
     * 开始咨询
     */
    @PostMapping("/consultation/start")
    public Result<Boolean> startConsultation(@RequestParam Long appointmentId) {
        return Result.success(counselorService.startConsultation(appointmentId));
    }

    /**
     * 记录咨询内容
     */
    @PostMapping("/consultation/record")
    public Result<Boolean> recordConsultation(@RequestBody ConsultationRecord record) {
        return Result.success(counselorService.recordConsultation(record));
    }

    /**
     * 获取咨询记录
     */
    @GetMapping("/consultation/records")
    public Result<List<ConsultationRecord>> getConsultationRecords(@RequestParam Long counselorId) {
        return Result.success(counselorService.getConsultationRecords(counselorId));
    }

    /**
     * 更新咨询记录
     */
    @PutMapping("/consultation/record")
    public Result<Boolean> updateConsultationRecord(@RequestBody ConsultationRecord record) {
        return Result.success(counselorService.updateConsultationRecord(record));
    }

    /**
     * 获取学生评价
     */
    @GetMapping("/feedback")
    public Result<List<ConsultationRecord>> getStudentFeedback(@RequestParam Long counselorId) {
        return Result.success(counselorService.getStudentFeedback(counselorId));
    }

    /**
     * 回复学生反馈
     */
    @PostMapping("/feedback/reply")
    public Result<Boolean> replyToFeedback(
            @RequestParam Long recordId,
            @RequestParam String counselorFeedback) {
        return Result.success(counselorService.replyToFeedback(recordId, counselorFeedback));
    }
}